using KL.Core.Common.infrastructure;
using KL.Core.Common.Utils;
using KL.Core.Extensions.HostedService;
using KL.Standard.RabbitMQ;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace KL.Core.Extensions.MQ;
/// <summary>
/// Rabbitmq 配置
/// </summary>
public static class RabbitMqSetup
{
    /// <summary>
    /// Rabbitmq 设置
    /// </summary>
    /// <param name="services"></param>
    /// <exception cref="ArgumentNullException"></exception>
    public static void AddRabbitMqSetup(this IServiceCollection services)
    {
        if (services == null) throw new ArgumentNullException(nameof(services));
        services.AddSingleton(typeof(RabbitMQFactory<>));
        var flag = AppSettings.app(new string[] { "RabbitMq", "Enabled" });
        if (AppSettings.app(new string[] { "RabbitMq", "Enabled" }).ObjToBool())
        {
            services.AddSingleton<IHostedService,QueueConcumerService>();
        }
    }
}